package interaction.sampling;

import java.util.Collection;

public class SampleSet {
	private Sample[] samples;
	private Sample average;
	
	public SampleSet(Sample ... data) {
		samples = data;
	}
	
	public SampleSet(Collection<Sample> data)
	{
		this(collectionToArray(data));
	}
	
	private static Sample[] collectionToArray(Collection<Sample> data)
	{
		Sample[] samples = new Sample[data.size()];
		int i = 0;
		for (Sample s : data) {
			samples[i] = s;
			i++;
		}
		return samples;
	}
	
	public Sample getSampleAverage()
	{
		if (null == average) {
			average = Samples.average(samples);
		}
		return average;
	}
	
	public int getSampleSize()
	{
		return Samples.getMaximumSize(samples);
	}
	
	public NumericAnalyzer getAnalyzer(int index)
	{
		return Samples.select(samples, index).getAnalyzer();
	}
	
	public Sample getSizes()
	{
		Sample result = new Sample(samples.length);
		for (Sample s : samples) {
			result.add((float) s.size());
		}
		return result;
	}
	
	public SampleSet apply(Transform t)
	{
		Sample[] result = new Sample[samples.length];
		for (int i = 0; i< result.length; i++) {
			result[i] = t.apply(samples[i]);
		}
		return new SampleSet(result);
	}
}
